#pragma once

#include <vector>
#include <string>
#include "CFile.h"
#include "CNode.h"
#include "CMessage.h"



class CNode
{
public:
	
	struct connection
	{
		connection(CNode* n) {otherNode = n;}
		//~connection() {delete otherNode;}

		CNode* otherNode;
		double bw;
	};

	struct activeDL
	{
		activeDL(CFile* f) {file = f;}
		~activeDL() {delete file; delete source;}
		void setSource (CNode* s) {source = s;}

		CNode* source;
		double timeLeft;
		CFile* file;
	};


	enum Type {NONE, NORMAL, SUPER};

	std::vector< CFile > files;
	std::vector< CFile > filesDesired;
	
	typedef std::vector<CNode *>::iterator NIter;
	std::vector< connection > neighbors;
	std::vector< connection > children;

	std::vector< activeDL > dls;

	CNode();
	CNode(int xloc, int yloc);
	CNode(CNode::Type type, int xMax, int yMax, int idNum);
	~CNode();

	void Update(double time);
	void retXY(double &X, double &Y) {X = x; Y = y;}
	void addN(CNode* n);
	void addC(CNode* c);
	void remN(CNode* n);
	void remC(CNode* c);
	double getBW() {return bw;}
	double getDist(double someX, double someY);

	void printData(std::string fname);

	bool busy;

	void newMessage(CMessage newM);
private:
	int currentTime;
	Type t;
	int ID;
	double x, y;
	double bw; //The bandwidth of the current node's network connection.
	double compTime;
	double totalData;
	int comms; 
	//  Assumes upload/download bw's are the same: for future work!
};
